//
//  StudyCourseSynopsisViewController.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "StudyCourseSynopsisViewController.h"
#import "ZJSCSynopsisTableViewCell.h"
#import "ZJSCSynopsisSectionView.h"
#import "ZJSCSynopsisModel.h"
#define CellID @"ZJSCSynopsisTableViewCell"
#define SectionID @"ZJSCSynopsisSectionView"
@interface StudyCourseSynopsisViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    ZJSCSynopsisModel *_model;/**< 网络请求下来的model */
}
/** tableView */
@property (nonatomic, strong) UITableView *tableView;


@end

@implementation StudyCourseSynopsisViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewBGGrayColor];
    [self setupUI];
    [self initDataArray];
}
- (void)setupUI{
    [self.view addSubview:self.tableView];
}
- (void)initDataArray{
    __weak typeof(self) weakSelf = self;
    NSDictionary *dict = @{@"COURSEWARE_ID":@"7d296754-deab-49d6-8563-00461d719e4b"};
    [NetWorkingManager postWithUrlString:[NetWorkingURL courseware] Parameter:dict Success:^(id object) {
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {//
            _model = [ZJSCSynopsisModel yy_modelWithJSON:object];
            [weakSelf.tableView reloadData];
        }
    } Fail:^(id object) {
        
    }];


}
#pragma mark - UITableView 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (!_model) {
        return 0;
    }
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZJSCSynopsisTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
    
    if (indexPath.section == 1) {
        cell.isSynopsisIntroduce = YES;
    }else{
        cell.isSynopsisIntroduce = NO;
    }
    cell.model = _model;
    return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    ZJSCSynopsisSectionView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionID];
    if (section == 0) {
        view.titleLabel.text = @"主持人简介 :";
    }else{
        view.titleLabel.text = @"课程简介 :";
    }
    return view;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1) {
        _model.isSynopsisIntroduce = YES;
    }else{
        _model.isSynopsisIntroduce = NO;
    }
    return _model.cellHeight;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

#pragma mark - Setter


#pragma mark - Getters
- (UITableView *)tableView{
    if (_tableView == nil){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - self.view.width * 9 / 16 - 44 - TabbarHeight - 44 - navHeight) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 7.5 * [UIScreen zj_screenHScale])];
        view.backgroundColor = [UIColor viewBGGrayColor];
        _tableView.tableHeaderView = view;
        [_tableView  registerClass:[ZJSCSynopsisTableViewCell class] forCellReuseIdentifier: CellID];
        [_tableView registerClass:[ZJSCSynopsisSectionView class] forHeaderFooterViewReuseIdentifier: SectionID];
        
    }
    return _tableView;
}



@end
